home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / amok98-106 / amok98 / programminginoberon / rects2.mod < prev    next >
Text File  |  1993-10-07  |  940b  |  40 lines

  1. MODULE Rects;
  2. (* Very tiny graphics editor, Exercise 12.5, page 241 (same as version 1).
  3.     Note: In Programming in Oberon, this module is called Rectangles. It
  4.     is renamed to avoid naming conflict with the standard Draw package *)
  5.  
  6. IMPORT Graphs, Shapes;
  7. TYPE 
  8.     Rect* = POINTER TO RectDesc;
  9.     RectDesc* = RECORD(Graphs.FigureDesc)    
  10.         x*, y*, w*, h*: INTEGER;
  11.     END;
  12.  
  13. PROCEDURE Min(x, y: INTEGER): INTEGER;
  14. BEGIN IF x < y THEN RETURN x ELSE RETURN y END
  15. END Min;
  16.  
  17. PROCEDURE Draw*(r: Graphs.Figure);
  18. BEGIN
  19.     WITH r: Rect DO 
  20.         Shapes.Rect(r.x, r.y, r.w, r.h)
  21.     END
  22. END Draw;
  23.  
  24. PROCEDURE NewFigure*(): Graphs.Figure;
  25. VAR r: Rect;  x1, y1, x2, y2: INTEGER;  
  26. BEGIN
  27.     NEW(r);  
  28.     r.draw := Draw;  
  29.     Graphs.spanVect(x1, y1, x2, y2);
  30.     r.x := Min(x1, x2);  r.y := Min(y1, y2);  
  31.     r.w := ABS(x2 - x1);  r.h := ABS(y2 - y1);
  32.     RETURN r
  33. END NewFigure;
  34.  
  35. PROCEDURE Set*;
  36. BEGIN  Graphs.newFigure := NewFigure;
  37. END Set;
  38.  
  39. END Rects.    (* Copyright M. Reiser, 1992 *)
  40.